package edu.sctu.xiangkun.day201506.day20150608;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
* Created by user21 on 2015/6/12.
*/
public class ThreadUtil{
    private int index = 0;
    private boolean ture = false;
    public void startThread(HashMap<String,Integer> map,PeopleAppbean people){
        index = map.get(people.getStart());
       new Thread(){
           @Override
           public void run(){
               super.run();
               if(map.size() > index){
                   System.out.println(index);
                   while(ture){
                       Set<Map.Entry<String,Integer>> mapset = map.entrySet();
                       Iterator ite = mapset.iterator();
                       while(ite.hasNext()){
                           @SuppressWarnings("unchecked")
                           Map.Entry<String,Integer> next = (Map.Entry<String,Integer>) ite.next();
                           if(next.getValue() == index){
                               index += 1;
                               System.out.println("下一站为："+next.getKey());
                               if(map.get(people.getEnd()) == next.getValue()){
                                   System.out.println("出站");
                                   System.exit(0);
                               }
                           }
                           try{
                               Thread.sleep(20000);
                           } catch (Exception e) {
                               e.printStackTrace();
                           }
                       }

                   }
               }
           }
       }.start();
    }
}
